<div id="packing_list_view_content">
<h1>View packing_list #<?php echo $model->id; ?></h1>

<?php 
$this->menu = array(
    array('label'=>'New packing list','url'=>array('create')),
    array('label'=>'Manage packing list','url'=>array('update','id'=>$model->id)),
    array('label'=>'List packing list','url'=>array('list')),
);
?>
<?php
$this->widget('zii.widgets.CDetailView', array(
    'data' => $model,
    'attributes' => array(
        'date:date:Date',
        'attn:text:Person in charge',
        'handlingAgent.cname:text:Handling agent',
        'clearingAgent.cname:text:Clearing agent',
        'notifyParty.cname:text:Notify party / Consignee',
        'shippingLine.cname:text:Carrier',
        'pol:text:Port of loading',
        'pod:text:Port of discharge',
        'subject:text:Subject / Topic',
    ),
));
?>
<div style="text-align: center">
<?php
    $this->widget('application.widgets.RiotingNerds.Button', array(
        'name' => 'choose_export',
        'caption' => 'Add export information',
        'value' => "choose_export",
    ));
    $this->widget('application.widgets.RiotingNerds.Button', array(
        'name' => 'make_report',
        'caption' => 'Make report',
        'value' => "make_report",
    ));
?>
</div>
<div class="section clear">
    <div class="span-10 column">
        <h5>Cargos in packing list</h5>
    </div>
    <div class="column last">
        <?php
            $this->widget('application.widgets.RiotingNerds.Button', array(
                'name' => 'choose_cargo',
                'caption' => 'Add cargo',
                'value' => "choose_cargo",
            ));
        ?>
    </div>
</div>
<div class="row clear">
	<?php echo CHtml::label("Search",'search'); ?>
	<?php echo CHtml::textField('search',''); ?>
	<?php echo CHtml::link('Search','#',array('grid_id'=>'packing_list_cargo','id'=>'search')); ?>
	</div>
<?php
	$this->widget('zii.widgets.grid.CGridView',array(
			'id'=>"packing_list_cargo",
			'dataProvider'=>$cargo->inPacking_list(),
			'columns'=>array(
				array(
					'value'=>'$data->allPackage()',
					'header'=>'Package marking',
					'type'=>'text',
				),
				array(
					'class'=>'CLinkColumn',
					'header'=>'Marking',
					'labelExpression'=>'$data->marking',
					'urlExpression'=>'CHtml::normalizeUrl(array("cargo/view","id"=>$data->id))'
				),
				array(
					'value'=>'$data->consignee->cname',
					'header'=>'Consignee',
				),
				array(
				'header'=>'Dimension',
				'value'=>'$data->dimension->qty.$data->dimension->qty_type." / ".$data->dimension->wt.$data->dimension->wt_type." / ".$data->dimension->m3',
				),
				array(
					'class'=>'CButtonColumn',
					'template'=>'{update}{delete}',
					'updateButtonUrl'=>'CHtml::normalizeUrl(array("packing_list_packages_cargo/create","cargo_id"=>$data->id))',
					'deleteButtonUrl'=>'CHtml::normalizeUrl(array("packing_list/removecargo","cargo_id"=>$data->id,"id"=>'.$model->id.'))',
					'updateButtonOptions'=>array('id'=>'cargo-grid-update','dialog_width'=>'650'),
					'deleteButtonOptions'=>array('id'=>'remove_cargo'),
				),
			),
		));
?>


<div class="section clear">
    <div class="span-10 column">
        <h5>Packages of packing list</h5>
    </div>
    <div class="column last">
        <?php
            $this->widget('application.widgets.RiotingNerds.Button', array(
                'name' => 'add_package',
                'caption' => 'Add package',
                'value' => "add_package",
            ));
        ?>
    </div>
</div>
<div class="row clear">
    <?php echo CHtml::label("Search",'search'); ?>
    <?php echo CHtml::textField('search',''); ?>
    <?php echo CHtml::link('Search','#',array('grid_id'=>'warehousecargo-grid','id'=>'search')); ?>
</div>
<?php
$this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'packing_list_packages',
    'dataProvider' => $package->search(),
    'columns' => array(
        'marking:text:Marking',
        array(
            'name' => 'wt',
            'header' => 'Weight',
            'value' => '$data->detail->wt.$data->detail->wt_type',
        ),
        array(
            'name' => 'length',
            'value' => '$data->detail->length',
        ),
        array(
            'name' => 'width',
            'value' => '$data->detail->width',
        ),
        array(
            'name' => 'height',
            'value' => '$data->detail->height',
        ),
        array(
            'class' => 'CButtonColumn',
            'viewButtonUrl' => 'CHtml::normalizeUrl(array("/packing_list_packages/view","id"=>$data->id))',
            'viewButtonOptions' => array('id' => 'view'),
            'updateButtonUrl' => 'CHtml::normalizeUrl(array("/packing_list_packages/update","id"=>$data->id))',
            'updateButtonOptions' => array('id' => 'update', 'dialog_width' => '400'),
            'deleteButtonUrl' => 'CHtml::normalizeUrl(array("/packing_list_packages/delete","id"=>$data->id))',
            'deleteButtonOptions' => array('id' => 'delete'),
        ),
    ),
));
?>
</div>
<?php
if(Yii::app()->request->enableCsrfValidation)
{
	$csrfTokenName = Yii::app()->request->csrfTokenName;
	$csrfToken = Yii::app()->request->csrfToken;
	$csrf = "\n\t\tdata:{ '$csrfTokenName':'$csrfToken' },";
}
else
	$csrf='';
$packageViewUrl = CHtml::normalizeUrl(array('packing_list/showallpackages','packing_list_id'=>$model->id));
$warehouseCargoUrl = CHtml::normalizeUrl(array('packing_list/showwarehousecargo','packing_id'=>$model->id));
$makeReportUrl = CHtml::normalizeUrl(array('makereport','id'=>$model->id));
$validate = (Yii::app()->request->enableCsrfValidation)?",".Yii::app()->request->csrfTokenName.":'".yii::app()->request->csrfToken."'":'';
$script =<<<EOD
$("#content").slideContent({width:'370'});
$('#update').live('click',function(){
	var gridID = $(this).parents('.grid-view').attr('id');
	var dialogWidth = parseInt($(this).attr('dialog_width'));
	var dialogButton = {
		Update:function(){
			var constructor = $(this);
			$.packing_list_packages_update_form = {
				afterSubmit:function(data){
					$.fn.yiiGridView.update(gridID,{});
					$(constructor).dialog('close');
				}
			};
			$(this).find('[type=submit]').click();
		}
	};
	$.simplelogdialog({url:$(this).attr('href')},{width:dialogWidth},dialogButton);
	return false;
});
$('#cargo-grid-update').live('click',function(){
	var gridID = $(this).parents('.grid-view').attr('id');
	var dialogWidth = parseInt($(this).attr('dialog_width'));
	var dialogButton = {
		Update:function(){
			var constructor = $(this);
			$.packing_list_packages_cargo = {
				afterSubmit:function(data){
					$.fn.yiiGridView.update(gridID);
					$(constructor).dialog('close');
				}
			};
			$(this).find('[type=submit]').click();
		}
	};
	$.simplelogdialog({url:$(this).attr('href')},{width:dialogWidth},dialogButton);
	return false;
});

$('#remove_cargo').live('click',function(){
	if(!window.confirm("Do you sure want to delete this?"))
		return false;
	var datas = {id:$(this).attr('data_id'){$validate}};
	var grid = $(this).parents('.grid-view').attr('id');
	var ajaxOptions = {
		data:datas,
		url:$(this).attr('href'),
		success:function(data,status){
			$.fn.yiiGridView.update(grid);
			return;
		}
	};
	$.simplelogajax.ajax(ajaxOptions);
	return false;
});
$('a#add_cargo').live('click',function(){
	var ajaxOptions = {
		url:$(this).attr('href'),
		$csrf
		complete:function(){
                    $.fn.yiiGridView.update('warehousecargo_grid');
                    $.fn.yiiGridView.update('packing_list_cargo');
                    return;
		}
	};
	$.simplelogajax.ajax(ajaxOptions);
	return false;
});
$('#choose_cargo').click(function(){
    $(this).ToggleSlide('content','$warehouseCargoUrl','Choose cargo');
    return false;
});
$('#menu_package').click(function(){
	var dialogButton = {
		Add:function(){
			var constructor = $(this);
			$.packing_list_packages_form = {
				afterSubmit:function(data){
					var container = $('#packages');
					$(container).subcontent({url:'$packageViewUrl',data:{id:data.id}});
					$(constructor).dialog('close');
				}
			};
			$(this).find('#packing-list-packages-form').find('[type=submit]').click();
		}
	};
	$.simplelogdialog({url:$(this).attr('href')},{width:700},dialogButton);
	return false;
});
$('input#search').keypress(function(event){
	if(event.keyCode == '13'){
		$(this).next('a#search').click();
	}
});
$('a#search').click(function(){
	var searchInput = $(this).prev('input#search');
	$.fn.yiiGridView.update($(this).attr('grid_id'),{data:{searchText:$(searchInput).val()}});
	return false;	
});
$('#menu_create_export').click(function(){
    $.simplelogdialog.Form({url:$(this).attr('href')},{width:370,height:440});
    return false;
});
$('#make_report').click(function(){
    $.simplelogajax.popup('$makeReportUrl');
});
EOD;
$cs = Yii::app()->getClientScript();
$cs->registerScript('Packing_list#View',$script);
?>